public class StudenT {
    private final int id; // 声明为final，表示id一旦设置就不允许更改
    private String name;  // 如果name允许更改，则保持不变

    public StudenT(int id, String name) {
        if (id <= 0) {
            throw new IllegalArgumentException("ID must be positive.");
        }
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("Name cannot be null or empty.");
        }
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        // 如果需要允许修改id，这里应加入校验逻辑
        this.id = id; // 注意：这里违反了id作为final的原则，如果不需要修改id，应该删除此方法
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("Name cannot be null or empty.");
        }
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + (name != null ? name : "null") + '\'' + // 避免NullPointerException
                '}';
    }
}
